package 力扣._00周赛._376周赛.问题2;

import java.util.Arrays;

class Solution {
    public int[][] divideArray(int[] nums, int k) {
        //排序
        Arrays.sort(nums);
        for (int i = 0; i < nums.length; i += 3) {
            for (int j = i + 1; j < i + 3; j++) {
                if (nums[j] - nums[i] > k)
                    return new int[1][0];
            }
        }
        int[][] r = new int[nums.length / 3][3];
        for (int i = 0; i < nums.length; i += 3) {
            for (int j = i; j < i + 3; j++) {
                r[i / 3][j - i] = nums[j];
            }
        }
        return r;

    }
}